import 'package:flutter/material.dart';

/**
 * Widget Text使用
 */
main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HYHomePage(),
    );
  }
}

class HYHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('基础Widget'),
      ),
      body: HYHomeContent(),
    );
  }
}

class HYHomeContent extends StatefulWidget {
  @override
  _HYHomeContentState createState() => _HYHomeContentState();
}

class _HYHomeContentState extends State<HYHomeContent> {
  @override
  Widget build(BuildContext context) {
    return TextRichDemo();
  }
}

class TextRichDemo extends StatelessWidget {
  const TextRichDemo({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Text.rich(
      TextSpan(
//          text: 'Hello Word',
//          style: TextStyle(color: Colors.red),
          children: [
            TextSpan(
              text: 'Hello Word',
              style: TextStyle(color: Colors.red),
            ),
            TextSpan(
              text: 'Hello Flutter',
              style: TextStyle(color: Colors.green),
            ),
            WidgetSpan(
                child: Icon(
                  Icons.favorite,
                  color: Colors.red,
                )),
            TextSpan(
              text: 'Hello Dart',
              style: TextStyle(color: Colors.blue),
            )
          ]),
    );
  }
}

class TestDemo extends StatelessWidget {
  const TestDemo({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Text(
      '湘帘卷处，甚离披翠影，绕檐遮住。\n小立吹裙，常伴春慵，掩映绣床金缕。芳心一束浑难展，清泪裹、隔年愁聚。更夜深、细听空阶雨滴，梦回无据。\n正是秋来寂寞，偏声声点点，助人难绪。缬被初寒，宿酒全醒，搅碎乱蛩双杵。\n西风落尽庭梧叶，还剩得、绿阴如许。想玉人、和露折来，曾写断肠句。',
      textAlign: TextAlign.center,
      maxLines: 3,
      overflow: TextOverflow.ellipsis,
//      textScaleFactor: 1.5,//缩放多少倍
      style: TextStyle(
        fontSize: 20,
        color: Colors.pink,
        fontWeight: FontWeight.bold,
      ),
    );
  }
}
